﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace array_calculate
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();
            Console.WriteLine("输入一个整数数组，并以非数字字符结尾(输入一个数字后按回车继续输入)：");
            while(true) 
            {
                string input = Console.ReadLine();
                if (int.TryParse(input, out int number))
                {
                    list.Add(number);
                }
                else
                    break;
            }
            if (list.Count == 0)
            {
                Console.WriteLine("未输入任何有效整数，程序结束。");
                return;
            }
            int Max = int.MinValue;
            int Min = int.MaxValue;
            int Sum = 0;
            for (int i = 0; i < list.Count; i++) 
            {
                if (list[i] > Max)
                { Max = list[i]; }
                if (list[i] < Min)
                { Min = list[i]; }
                Sum += list[i];
            }
            double Average = (double)Sum / list.Count; 
            Console.WriteLine("最大值为："+Max);
            Console.WriteLine("最小值为："+Min);
            Console.WriteLine("平均值为："+Average);
            Console.WriteLine("所有元素和为："+Sum);
        }
    }
}
